<?php
define("_DEBUG", false);

class cDB {
	var $con;
	var $host;
	var $user;
	var $password;

	 function __construct(){
		$this->host = DB_HOST;
		$this->user = DB_USER;
		$this->password = DB_PASSWORD;

		$this->_open();
		$this->_select(DB_NAME);
	}

	private function _open(){
		// DEBUG
		if (_DEBUG == true) {
			echo "<br/>bt_DBUtil::open()<br/>";
		}
		//return mysql_close($this->con);
		return $this->con = mysql_connect($this->host, $this->user, $this->password);
	}
	function _select($dbname) {
		$r1 = mysql_select_db($dbname, $this->con);
		$r2 = mysql_query("SET NAMES UTF8");
		return $r1&&$r2;
	}

	 function getCon() {
		return $this->con;
	}
	
	function setDB($dbname) {
		$r1 = mysql_select_db($dbname, $this->con);
		$r2 = mysql_query("SET NAMES UTF8");
		return $r1&&$r2;
	}
	
	function open($host,$user,$pw,$name) {
		// DEBUG
		if (_DEBUG == true) {
			echo "<br/>bt_DBUtil::open(host,user,pw)<br/>";
		}
		$this->con = mysql_connect($host, $user, $pw);
		return $this->_select($name);
	}
	function close() {
		// DEBUG
		if (_DEBUG == true) {
			echo "<br/>bt_DBUtil::close()()<br/>";
		}
		return mysql_close($this->con);
	}
	function beginTransaction() {
		mysql_query("SET AUTOCOMMIT=0", $this->con);
		mysql_query("BEGIN", $this->con);
	}
	function commit() {
		if (_DEBUG == true)
			echo "<br/>bt_DBUtil::COMMIT()<br/>";
		mysql_query("COMMIT", $this->con);
	}
	function rollback() {
		if (_DEBUG == true)
			echo "<br/>bt_DBUtil::ROLLBACK()<br/>";
		mysql_query("ROLLBACK", $this->con);
	}
	function success($rst) {
		if ($rst != NULL && $rst)
			return true;
		else
			return false;
	}
}

?>
